package com.example.hospitalsystem.controller;

import com.example.hospitalsystem.pojo.dto.department.AddDepartmentDto;
import com.example.hospitalsystem.pojo.dto.department.DepartmentPageQueryDto;
import com.example.hospitalsystem.pojo.dto.pharmacy.AddPharmacyDto;
import com.example.hospitalsystem.pojo.dto.pharmacy.PharmacyPageQueryDto;
import com.example.hospitalsystem.pojo.entity.Pharmacy;
import com.example.hospitalsystem.result.Result;
import com.example.hospitalsystem.service.DepartmentService;
import com.example.hospitalsystem.service.PharmacyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pharmacy")
@Tag(name="9.药品模块")
public class PharmacyController {

    @Autowired
    private PharmacyService pharmacyService;

    @Operation(summary = "获取所有药品信息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/getAllPharmacyInfo")
    public Result<Object> getAllPharmacyInfo(@RequestBody PharmacyPageQueryDto pharmacyPageQueryDto){
        return pharmacyService.getAllPharmacyInfo(pharmacyPageQueryDto);
    }

    @Operation(summary = "添加药品", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/addPharmacyInfo")
    public Result<Object> addPharmacy(@RequestBody AddPharmacyDto addPharmacyDto){
        return pharmacyService.addPharmacy(addPharmacyDto);
    }

    @Operation(summary = "删除药品信息", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deletePharmacy/{id}")
    public Result<Object> deletePharmacy(@PathVariable("id") int id){
        return pharmacyService.deletePharmacy(id);
    }

    @Operation(summary = "搜索药品", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/search")
    public Result<Object> searchPharmacy(String key){
        List<Pharmacy> list = pharmacyService.searchPharmacy(key);
        return Result.ok(list);
    }
}
